<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){

        $TypeModel=M('types');//表明,conf中定义前缀
		$types=$TypeModel->order('tid asc')->select(); //desc降序 asc升序

		//dump($top);
		$this->types=$types;//name属性对应的值 $this->对应值=$top;
		$types = M('types');
	    $this->display();

    }


public function foodslist(){
		$tid=$_GET['tid'];
		$foodsModel=M('foods');//表明,conf中定义前缀
		$foods=$foodsModel->where("tid=$tid")->order('tid asc')->select(); //desc降序 asc升序

		//dump($top);
		$this->foods=$foods;//name属性对应的值 $this->对应值=$top;
    $foods = M('foods');

    $qrcodenum=$foods->where("tid=$tid")->count();
    $Page = new \Think\Page($qrcodenum,3);
    $Page->setConfig('header', '共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;
每页<b>3</b>条&nbsp;&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页');
    $Page->setConfig('prev','上一页');
    $Page->setConfig('next','下一页');
    $Page->setConfig('last','末页');
    $Page->setConfig('first','首页');
    $Page->setConfig('theme',' %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
    $this->pageNav=$Page->show();//在页面{pageNav}
        //$this->link=$Page->show();
        $this->qrcodeList=$foods->where("tid=$tid")->limit($Page->firstRow,3)->select();

        $this->display();
    }
    public function collection(){
        $collection=M("collection");
        if($collection->create()){
  // if($_FILES['file']['error']==0) {
  //   $logoinfo=$this->upload();
  //   $pname=$logoinfo['file']['savename'];
  // }else{
  //   $pname="defaule.jpg";
  // }
  // $collection->photo=$pname;
   

    if(false !==$collection->add()){
      $this->success('收藏成功！');
    }else{$this->error('数据错误');
  }
}else{
  $this->error($collection->getError());
}
        
        $this->display();
    }





public function thumb(){
    $image=new\Think\Image();
    $image->open('./1.jpg');
    //按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
    $image->thumb(150,150)->save('./thumb.jpg');
      }

}